package scala.day01

object Demo11Ex {
  def main(args: Array[String]): Unit = {
    val a = new A("001", "张三")
    a.print()


    val lisi = new B("003", "李四", 24)

    lisi.print()
  }
  class A(id:String,name:String){
    println("A的默认构造函数")
    val _id:String = id
    val _name:String = name
    def print():Unit = {
      println(_id+"\t"+_name)
    }

}
  /**
    * 类的继承，会继承父类的属性和方法
    *
    * 继承的时候调用父类的构造函数
    *
    *
    */
  class B(id:String,name:String,age:Int)extends A(id,name){
    println("B的构造方法")
    val _age:Int = age

    //重写父类日的方法
    override def print(): Unit = {
      println(_id + "\t" + _name + "\t" + _age)
    }
  }
}
